<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改学生信息</title>
<link rel="stylesheet" href="css/stuAdd.css" />
<link rel="stylesheet" href="css/magicStyle.css" />
<script
	src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.2.min.js"></script>
<script language="javascript" src="js/jQuery.form.js"></script>
<script language="javascript" src="js/checkInfo.js"></script>
<script language="javascript">
	// 提交信息
	function toSubmit() {
		//获得学历
		var a = document.getElementById("myselect");
		var b = a.options[a.selectedIndex].value;
		//获得性别
		var radio = document.getElementsByName("gender");
		for (i = 0; i < radio.length; i++) {
			if (radio[i].checked) {
				var c = radio[i].value;
			}
		}
		//所有数据都符合要求时
		if (flag_pwd && flag_email && flag_enter && flag_birth) {
			//获得文件名
			var pos1 = myform.photo.value.lastIndexOf('/');
			var pos2 = myform.photo.value.lastIndexOf('\\');
			var pos = Math.max(pos1, pos2);
			var photoAdd = myform.photo.value.substring(pos+1);
			//判断文件格式
			if (!photoAdd.match(/.jpg|.jpeg|.gif|.png|.bmp/i)) {
	                alert("您上传的不是图片文件！");
	                return false;
	        }
			//限制上传文件大小
			if(myform.photoFile.value=="") {
				// ignore
			} else {
				if(((myform.photoFile.files[0].size).toFixed(2))>=(3*1024*1024)){       
					alert("图片大小不能大于3MB！");
					return false;
				}
			}
			//组合参数
			var param = 'StudentUpdate?' + "no=" + myform.no.value
					+ "&name=" + myform.name.value + "&pwd=" + myform.pwd.value
					+ "&email=" + myform.email.value + "&entranceTime="
					+ myform.entranceTime.value + "&sex=" + c + "&photo="
					+ photoAdd + "&birth=" + myform.birth.value + "&education="
					+ b;
			param = encodeURI(param);
			param = encodeURI(param);
			var option = {
				url : param,
				type : 'POST',
				headers : {
					"ClientCallMode" : "ajax"
				}, // 添加请求头部
				success : function(data) {
					alert("提交成功！");
					window.location.href="StudentList";
				},
				error : function(data) {
					alert("提交失败！");
				}
			};
			$("#myform").ajaxSubmit(option);
			return false; // 最好返回false，因为如果按钮类型是submit,则表单自己又会提交一次;返回false阻止表单再次提交
		} else {
			alert("您输入的信息有误！请检查后提交！");
		}
	}
</script>
</head>

<body>
	<div class="top">
		<p>修改学生信息</p>
	</div>
	<div class="container">
		<form id="myform" name="myform" class="myform" action="" method="post"
			enctype="multipart/form-data">
			<div class="table_container">
				<table align="center" bordercolor="#CCCCCC" border="1"
					cellpadding="12" cellspacing="0">
					<tr>
						<td>学号</td>
						<td><input class="myinput" id="no" name="no" type="text"
							value="${requestScope.student.no}" disabled="disabled" /> <br />
							<span id="warning_no"> *学号由4位数字组成，首位数字不能为0 </span></td>
					</tr>
					<tr>
						<td>姓名</td>
						<td><input class="myinput" id="name" name="name" type="text"
							value="${requestScope.student.name}" disabled="disabled" /> <br />
							<span id="warning_name"> *姓名只能由汉字或字母组成 </span></td>
					</tr>
					<tr>
						<td>密码</td>
						<td><input class="myinput" id="pwd" name="pwd"
							type="password" onblur="checkPwd(this.value)" /> <br />
							<div id="correct_pwd" class="icon">
								<img src="images/correct.png" />
							</div>
							<div id="error_pwd" class="icon">
								<img src="images/error.png" />
							</div> <span id="warning_pwd"> *请输入6位以上（包含6位）的密码 </span></td>
					</tr>
					<tr>
						<td>邮箱</td>
						<td><input class="myinput" id="email" name="email"
							type="text" onblur="checkEmail(this.value)" /> <br />
							<div id="correct_email" class="icon">
								<img src="images/correct.png" />
							</div>
							<div id="error_email" class="icon">
								<img src="images/error.png" />
							</div> <span id="warning_email"> 邮箱必须包含@，例如：panda@qq.com </span></td>
					</tr>
					<tr>
						<td>入学时间</td>
						<td><input class="myinput" id="entranceTime"
							name="entranceTime" type="text" onblur="checkEnter(this.value)" />
							<br />
							<div id="correct_enter" class="icon">
								<img src="images/correct.png" />
							</div>
							<div id="error_enter" class="icon">
								<img src="images/error.png" />
							</div> <span id="warning_enter"> *请输入入学时间，格式为2000-01-01 </span></td>
					</tr>
					<tr>
						<td>性别</td>
						<td>
							<div class="radio">
								<input id="male" type="radio" name="gender" value="男生"
									checked="checked"> <label for="male">男生</label> <input
									id="female" type="radio" name="gender" value="女生"> <label
										for="female">女生</label>
							</div>
						</td>
					</tr>
					<tr>
						<td>头像</td>
						<td>
							<div class="file-box">
								<input id="photo" name="photo" class="myinput" type="text"
									value="${requestScope.student.photo}" style="width: 170px;" disabled="disabled"/>
								<input class="uploadBtn" type="button" value="选择文件" /> <input
									name="photoFile" class="photoFile" type="file" id="photoFile"
									size="20"
									onchange="document.getElementById('photo').value=this.value" />
							</div>
						</td>
					</tr>
					<tr>
						<td>生日</td>
						<td><input class="myinput" id="birth" name="birth"
							type="text" onblur="checkBirth(this.value)" /> <br />
							<div id="correct_birth" class="icon">
								<img src="images/correct.png" />
							</div>
							<div id="error_birth" class="icon">
								<img src="images/error.png" />
							</div> <span id="warning_birth"> *请输入生日日期，格式为2000-01-01 </span></td>
					</tr>
					<tr>
						<td>学历</td>
						<td><select id="myselect" class="myselect" name="myselect">
								<option value="本科生">本科生</option>
								<option value="硕士生">硕士生</option>
								<option value="博士生">博士生</option>
						</select></td>
					</tr>
				</table>
			</div>
			<div class="button_container">
				<button type="button" onclick="toSubmit()">提 交</button>
				<button type="reset">重 置</button>
				<button type="button" onclick="history.back()">返
					回</button>
			</div>
		</form>
	</div>
</body>
</html>